package io.itit.ecp.admin.provide.helper.datarangelevel;

import io.itit.ecp.admin.common.enums.IDataRangeEnums;
import io.itit.ecp.admin.server.entity.SceneRoomEntity;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.schema.Table;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 数据范围 按楼层
 */
@Component
public class DataRangeLevelFloorHelper extends AbsDataRangeLevelHelper {

    @Override
    public IDataRangeEnums.RangeLevel rangeLevel() {
        return IDataRangeEnums.RangeLevel.rangeLevelFloor;
    }

    @Override
    public List<SceneRoomEntity> listByScene(Collection<String> sceneIds) {
        return listByFloor(sceneIds);
    }

    @Override
    public void processDataRange(List<SceneRoomEntity> roomList) {
        String userId = getUserId();
        putRangeLevelProject(userId, roomList);
        putRangeLevelEdifice(userId, roomList);
        putRangeLevelFloor(userId, roomList);
        putRangeLevelCompany(userId, roomList);
    }

    @Override
    public Expression getSqlSegment(Table table, Map<String, List<String>> tableMap) {
        String userId = getUserId();
        String tableName = table.getName();
        List<String> columnList = tableMap.get(tableName);

        Expression projectExpression = buildProjectExpression(userId, table, columnList);
        Expression edificeExpression = buildEdificeExpression(userId, table, columnList);
        Expression floorExpression = buildFloorExpression(userId, table, columnList);
        Expression companyExpression = buildCompanyExpression(userId, table, columnList);

        return buildExpression(projectExpression, edificeExpression, floorExpression, companyExpression);
    }

}
